﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YwhLib;

namespace YwhCore
{
    public class PhaseService
    {
        public static QueryRsp<Phase> Save(Phase phase)
        {
            QueryRsp<Phase> rsp = new QueryRsp<Phase>();

            ConfigService.Fsql.InsertOrUpdate<Phase>().SetSource(phase).ExecuteAffrows();

            return rsp;
        }

        public static QueryRsp<Phase> List(int PageNumber, int PageSize, int phaseNo = 0)
        {
            long l = 0;
            QueryRsp<Phase> query = new QueryRsp<Phase>();
            if (phaseNo == 0)
            {
                query.Items = ConfigService.Fsql.Select<Phase>().Count(out l).Page(PageNumber, PageSize).ToList();
            }
            else
            {
                query.Items = ConfigService.Fsql.Select<Phase>().Where(f => f.PhaseNo == phaseNo).Count(out l).Page(PageNumber, PageSize).ToList();
            }
            //query.Items = ConfigService.Fsql.Select<Phase>().Count(out l).Page(PageNumber, PageSize).ToList();
            query.Total = (int)l;
            return query;
        }

        public static QueryRsp<Phase> Update(Phase phase)
        {
            QueryRsp<Phase> rsp = new QueryRsp<Phase>();

            ConfigService.Fsql.Update<Phase>().Set(a => a.PhaseNo, 1).ExecuteAffrows();

            return rsp;
        }

        public static QueryRsp<Phase> Delete(Phase phase)
        {
            QueryRsp<Phase> rsp = new QueryRsp<Phase>();

            ConfigService.Fsql.Delete<Phase>().Where(x => x.PhaseNo == phase.PhaseNo).ExecuteAffrows();

            return rsp;
        }
    }
}
